<?php

namespace App\Http\Controllers;

use EasyWeChat\Foundation\Application;
use Illuminate\Http\Request;

class MenuController extends Controller
{
    public $menu;
    public function __construct(Application $app)
    {
        $this->menu = $app->menu;
    }

    /**
     * 自定义菜单
     */
    public function menu()
    {
        $buttons = [
            [
                "type" => "click",
                "name" => "click me",
                "key"  => "you_click_me"
            ],
            [
                "name"       => "二级菜单",
                "sub_button" => [
                    [
                        "type" => "view",
                        "name" => "搜索",
                        "url"  => "http://www.soso.com/"
                    ],
                    [
                        "type" => "view",
                        "name" => "视频",
                        "url"  => "http://v.qq.com/"
                    ],
                    [
                        "type" => "click",
                        "name" => "赞一下我们",
                        "key" => "Hedy_best"//根据不同的key执行相应的事件
                    ],
                ],
            ],
        ];
        $this->menu->add($buttons);
        return 'success';
    }

    /**
     * 获取菜单
     * @return \EasyWeChat\Support\Collection
     */
    public function all()
    {
        return $this->menu->current();
    }
}
